package edu.hm.devcamp.presentation.activities;

import edu.hm.devcamp.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LayoutAnimationController;

public class SplashScreen extends Activity {
	
	protected boolean _active = true;
	protected int _splashTime = 1500; // time to display the splash screen in ms
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        
        View splashScreen = (View) findViewById(R.id.splash);
        
        
        Animation anim1 = new AlphaAnimation(0.0f, 1.0f);
        anim1.setDuration(2000);
        
        
//		
		splashScreen.startAnimation(anim1);
		        
        Thread splashTread = new Thread() {
            @Override
            public void run() {
            	
                try {
                    int waited = 0;
                    while(_active && (waited < _splashTime)) {
                        sleep(100);
                        if(_active) {
                            waited += 100;
                        }
                    }
                } catch(InterruptedException e) {
                    // do nothing
                } finally {
                    finish();
                    //startActivity(new Intent("com.droidnova.android.splashscreen.MyApp"));
                    startActivity(new Intent(SplashScreen.this, PoiMap.class));                   
                }
            }
        };
        splashTread.start();
        
        
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            _active = false;
        }
        return true;
    }

}
